<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>注册</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="/game/Public/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/game/Public/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/game/Public/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/game/Public/admin/css/animate.css" rel="stylesheet">
    <link href="/game/Public/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <script>if(window.top !== window.self){ window.top.location = window.location;}</script>

</head>

<body class="gray-bg">

    <div class="middle-box middle-box-register text-center loginscreen   animated fadeInDown">
        <div>
            <div>
                <h1 class="logo-name">Game</h1>
            </div>
            <h3>欢迎注册游戏代理</h3>
            
        </div>
    </div>

    <div class="row" >
        <div class="col-sm-3" ></div>
                <div class="col-sm-6" >
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="commentForm" action="login.html">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">姓名：</label>
                                <div class="col-sm-5">
                                    <input id="truename" name="truename" minlength="2" type="text" class="form-control" required="" aria-required="true" placeholder="请输入2~4个中文字符">
                                </div>
                                <span class="cred">*</span><span class="cred t1 t"></span>
                            </div>
                            
                            <div class="form-group">
                                <label class="col-sm-4 control-label">身份证号码：</label>
                                <div class="col-sm-5">
                                    <input id="id_no" name="id_no" minlength="2" type="text" class="form-control" required="" aria-required="true" placeholder="请输入18位正确的身份证号码">
                                </div>
                                <span class="cred">*</span><span class="cred t2 t"></span>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">上级推荐码：</label>
                                <div class="col-sm-5">
                                    <input id="p_code" name="p_code" minlength="2" type="text" class="form-control" required="" aria-required="true">
                                </div>
                                <span class="cred t3 t"></span>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">密码：</label>
                                <div class="col-sm-5">
                                    <input id="password" type="password" class="form-control" name="password" placeholder="请输入6~20位非中文字符">
                                </div>
                                <span class="cred">*</span><span class="cred t5 t"></span>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">确认密码：</label>
                                <div class="col-sm-5">
                                    <input id="re_password" type="password" class="form-control" name="re_password" placeholder="请输入6~20位非中文字符">
                                </div>
                                <span class="cred">*</span><span class="cred t6 t"></span>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">手机号：</label>
                                <div class="col-sm-5">
                                    <input id="phone" name="phone" minlength="2" type="text" class="form-control" required="" aria-required="true" placeholder="请输入11位正确的手机号码">
                                </div>
                                <span class="cred">*</span><span class="cred t4 t"></span>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">验证码：</label>
                                <div class="col-sm-8" style="padding-left: 0px; ">
                                    <span class="col-sm-4">
                                    <input id="code" type="text" class="form-control " name="code" required="" aria-required="true"></span>
                                    <span class="input-group-btn"> <button type="button" class="btn btn-primary" id="get_code">发送验证码</button>

                                </div>
                                <span class="cred t7 t col-sm-5 col-sm-offset-4""></span>
                            </div>
                            
                            <div class="form-group">
                                <div class="col-sm-5 col-sm-offset-4">
                                    <button type="button" class="btn btn-primary block full-width m-b">注 册</button>
                                    <p class="text-muted text-center"><small>已经有账户了？</small><a href="login.html">点此登录</a></p>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                
            </div>
            <div class="col-sm-3" ></div>
                
    </div>

    <!-- 全局js -->
    <script src="/game/Public/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/game/Public/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- iCheck -->
    <script src="/game/Public/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });

        });
        //获取验证码
        $('#get_code').click(function(){
            var phone=$.trim($("#phone").val());
            if (phone == '') {
                    $('.t4').html('请输入手机号！');
                    return false;
                }else{
                    $('.t4').html('');
                }
            var time=10;
            $('#get_code').addClass("col-sm-4");
            $('#get_code').attr("disabled",'disabled');
            $('#get_code').html(time);
            setTime=setInterval(function(){
                if(time<=0){
                    clearInterval(setTime);
                    $('#get_code').removeClass("col-sm-4");
                    $('#get_code').attr("disabled",false);
                    $('#get_code').html('发送验证码');
                    return;
                }
                time--;
                $("#get_code").text(time);
            },1000);
            var url = "<?php echo U('Admin/Login/getCode');?>";
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: {phone:phone},
                success: function (data) {
                    if (data == 'phone_exist') {
                        $('.t').html('');
                        $('.t4').html('该手机号代理已存在！');
                        clearInterval(setTime);
                        $('#get_code').removeClass("col-sm-4");
                        $('#get_code').attr("disabled",false);
                        $('#get_code').html('发送验证码');
                    }else if (data == 'outtimes') {
                        alert('获取次数超限，稍后再试！');
                        clearInterval(setTime);
                        $('#get_code').removeClass("col-sm-4");
                        $('#get_code').attr("disabled",false);
                        $('#get_code').html('发送验证码');
                    }else if (data == 'success') {
                        alert('获取成功！');
                        

                    } else {
                        alert('获取失败！');
                        clearInterval(setTime);
                        $('#get_code').removeClass("col-sm-4");
                        $('#get_code').attr("disabled",false);
                        $('#get_code').html('发送验证码');
                    }
                }
            });
        })
            

    $('#role').change(function(){
        $('.t').html('');
        $("#truename").val('');
        $("#id_no").val('');
        $("#p_code").val('');
        $("#phone").val('');
        $("#password").val('');
        $("#re_password").val('');
        if ($(this).val()=='1') {
            $('.agent_div').removeClass('hide');
            $('#phone-title').html('手机号：');
            $('#phone').attr('placeholder','请输入11位正确的手机号码');
        }else{
            $('.agent_div').addClass('hide');
            $('#phone-title').html('用户名：');
            $('#phone').attr('placeholder','请输入用户名');
        }
    })
        $(".btn-primary").click(function() {
            var truename=$.trim($("#truename").val());
            var id_no=$.trim($("#id_no").val());
            var p_code=$.trim($("#p_code").val());
            var phone=$.trim($("#phone").val());
            var password=$.trim($("#password").val());
            var re_password=$.trim($("#re_password").val());            
            var code=$.trim($("#code").val());            
            if ( truename== '') {
                $('.t1').html('请输入代理姓名！');
                return false;
            }else{
                $('.t1').html('');
            }
            if (id_no == '') {
                $('.t2').html('请输入身份证号码！');
                return false;
            }else{
                $('.t2').html('');
            }
            if (password == '') {
                $('.t5').html('请输入密码！');
                return false;
            }else{
                $('.t5').html('');
            }
            if (re_password == '') {
                $('.t6').html('请确认密码！');
                return false;
            }else{
                $('.t6').html('');
            }
            if (re_password != password) {
                $('.t6').html('两次密码不一致！');
                return false;
            }else{
                $('.t6').html('');
            }
            if (phone == '') {
                $('.t4').html('请输入手机号！');
                return false;
            }else{
                $('.t4').html('');
            }
                
            if (code == '') {
                $('.t7').html('请输入验证码！');
                return false;
            }else{
                $('.t7').html('');
            }
            
            var params = {truename:truename,id_no:id_no,code:code,p_code:p_code,password:password,phone:phone};
            var url = "<?php echo U('Admin/Login/registerSave');?>";
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    if (data == 'id_exist') {
                        $('.t').html('');
                        $('.t2').html('该身份证代理已存在！');
                    }else if (data == 'phone_exist') {
                        $('.t').html('');
                        $('.t4').html('该手机号代理已存在！');
                    }else if (data == 'code_error') {
                        $('.t').html('');
                        $('.t4').html('验证码错误');
                    }else if (data == 'code_nexist') {
                        $('.t').html('');
                        $('.t3').html('该推荐码代理不存在！');
                        return false;
                    }else if (data == 'success') {
                        alert('注册成功！');
                        window.location.href = "<?php echo U('Admin/Login/login');?>";
                    } else {
                        alert('添加失败！');
                    }
                }
            });
        });
    </script>

    
    

</body>

</html>